package com.chenyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import com.chenyi.common.annotation.Log;
import com.chenyi.common.core.controller.BaseController;
import com.chenyi.common.enums.BusinessType;
import com.chenyi.common.core.domain.entity.SysShopMenu;
import com.chenyi.shop.service.ISysShopMenuService;
import com.chenyi.common.utils.poi.ExcelUtil;

/**
 * 菜单权限Controller
 * 
 * @author chenyi
 * @date 2020-10-24
 */
@RestController
@RequestMapping("/admin/shop/menu")
public class AdminShopMenuController extends BaseController
{
    @Autowired
    private ISysShopMenuService sysShopMenuService;

    /**
     * 查询菜单权限列表
     */
    @PreAuthorize("@admin.hasPermi('shop:menu:list')")
    @GetMapping("/list")
    public ResponseEntity<Object> list(SysShopMenu sysShopMenu)
    {
        List<SysShopMenu> list = sysShopMenuService.selectSysShopMenuList(sysShopMenu);
        return ResponseEntity.ok(list);
    }

    /**
     * 导出菜单权限列表
     */
    @PreAuthorize("@admin.hasPermi('shop:menu:export')")
    @Log(title = "菜单权限", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<Object> export(SysShopMenu sysShopMenu)
    {
        List<SysShopMenu> list = sysShopMenuService.selectSysShopMenuList(sysShopMenu);
        ExcelUtil<SysShopMenu> util = new ExcelUtil<SysShopMenu>(SysShopMenu.class);
        return util.exportExcel(list, "menu");
    }

    /**
     * 获取菜单权限详细信息
     */
    @PreAuthorize("@admin.hasPermi('shop:menu:query')")
    @GetMapping(value = "/{menuId}")
    public ResponseEntity<Object> getInfo(@PathVariable("menuId") Long menuId)
    {
        return ResponseEntity.ok(sysShopMenuService.selectSysShopMenuById(menuId));
    }

    /**
     * 新增菜单权限
     */
    @PreAuthorize("@admin.hasPermi('shop:menu:add')")
    @Log(title = "菜单权限", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Object> add(@RequestBody SysShopMenu sysShopMenu)
    {
        sysShopMenuService.insertSysShopMenu(sysShopMenu);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    /**
     * 修改菜单权限
     */
    @PreAuthorize("@admin.hasPermi('shop:menu:edit')")
    @Log(title = "菜单权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Object> edit(@RequestBody SysShopMenu sysShopMenu)
    {
        sysShopMenuService.updateSysShopMenu(sysShopMenu);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    /**
     * 删除菜单权限
     */
    @PreAuthorize("@admin.hasPermi('shop:menu:remove')")
    @Log(title = "菜单权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{menuIds}")
    public ResponseEntity<Object> remove(@PathVariable Long[] menuIds)
    {
        sysShopMenuService.deleteSysShopMenuByIds(menuIds);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
